package com.medical.system.controller;

import com.medical.system.service.LoginService;
import com.medical.system.service.SysUserService;
import com.medical.system.common.Result;
import com.medical.system.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "登录控制器")
@RestController
@RequestMapping("/admin/system/index")
public class LoginController {

    @Autowired
    private LoginService loginService;


    @Autowired
    private
    SysUserService sysUserService;

    @ApiOperation("登录请求")
    @PostMapping("/login")
    public Result login(@RequestBody LoginVo loginVo) {
        if (loginVo == null || "".equals(loginVo.getUsername()) || "".equals(loginVo.getPassword())) {
            return Result.build(null, 214, "账号不正确");
        }
        return this.loginService.login(loginVo);

    }

    @ApiOperation("获取登录角色信息")
    @GetMapping(value = "/info")
    public Result info(HttpServletRequest request) {
        //a.获取请求头的 token 字符串
        String token = request.getHeader("token");
        return this.loginService.loginInfo(token);
    }

    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public Result logout() {
        return this.loginService.logout();
    }
}
